#ifndef MSNTRANSPORT_H
#define MSNTRANSPORT_H

#ifdef WX_PRECOMP
#include "wx/wx.h"
#endif

#include <map>
#include <vector>

#include <curl/curl.h>

#include <map>


#include <wx/thread.h>
#include <wx/socket.h>

#include "tux.h"

class MsnConnection;

class MsnTransport : public wxThread
{
protected:
	//SB or NS
	wxString serverType;

	wxString serverAddress;
    int serverPort;

	wxString proxyAddress;
	int proxyPort;

protected:
	wxSocketBase* socket;

	MsnConnection* connection;

	bool connected;
	bool closed;

public:
	MsnTransport();
    virtual ~MsnTransport();

	void SetConnection(MsnConnection* conn);

	void SetServerType(const wxString& type){serverType = type;}

	void SetServerAddress(const wxString& server){serverAddress = server;}
	void SetServerPort(int port){serverPort = port;}

	void SetProxyAddress(const wxString& address){proxyAddress = address;}
	void SetProxyPort(int port){proxyPort = port;}

public:
	void Start();

	bool IsConnected();

	//this should be called from outside the current thread
    void CloseAndDelete();

	void OnExit();

public:
	virtual bool Open();
	virtual void Close();

	virtual void SendData(void* data, unsigned int size) = 0;

	wxString ReadLine();

	wxString ReadChunk(int len);

	void ReadChunk(char* buf, int len);

	void ReadData(wxMemoryBuffer& mb, int len);

	void SendData(const wxString& str);

};

#endif
